import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @ClassName Demo02_InputStreamReader
 * @Description 指定编码读取
 * @Author Li
 * @Date 2022/8/12 9:51
 * @ModifyDate 2022/8/12 9:51
 * @Version 1.0
 */
public class Demo02_InputStreamReader {
    public static void main(String[] args) throws IOException {
        // 定义文件路径，文件为gbk编码
        String filename = "src/part10/ch02_TransformStream/File_gbk.txt";
        InputStreamReader isr1 = new InputStreamReader(new FileInputStream(filename));
        InputStreamReader isr2 = new InputStreamReader(new FileInputStream(filename), "GBK");
        // 定义变量，保存字符
        int read;
        System.out.println("=====使用默认编码字符流读取=====");
        while ((read = isr1.read()) != -1) {
            System.out.println((char) read);
        }
        System.out.println("=====使用GBK编码字符流读取=====");
        while ((read = isr2.read()) != -1) {
            System.out.println((char) read);
        }
        isr1.close();
        isr2.close();
    }
}
